import com.woniu.user.domain.DeptAndDoctorName;
import com.woniu.user.domain.pbVo;
import com.woniu.user.mapper.DoctorMapper;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

public class paiban {
    @Autowired
    private static DoctorMapper doctorMapper;
    @Autowired
    @NonNull
    private static RedisTemplate redisTemplate;

    public static void main(String[] args) {

        paibanEnd(new Date());

        System.out.println("over");
    }



    //排班系统
    public static HashMap<Integer,ArrayList<Integer>> paibanEnd(Date date){
        //传入所有医生
        HashMap doctors = doctorIn();


        //执行排班
        HashMap<Integer,ArrayList<Integer>> paiban = paiban(doctors);
        //输出排班
        Object[] objects = paiban.keySet().toArray();
        System.out.println("本周的排班表是");
        for (int i = 0; i < objects.length; i++) {
            System.out.println("周"+objects[i]+":");
            for (int j = 0; j < 4; j++) {
                if(j==3){
                    System.out.println(doctors.get(paiban.get(objects[i]).get(j)));
                }else {
                    System.out.print(doctors.get(paiban.get(objects[i]).get(j))+" 和 ");
                }
            }
        }


        return paiban;
    }

    public static HashMap<Integer,ArrayList<Integer>> paiban(HashMap doctors){
        HashMap<Integer,ArrayList<Integer>> maps = new HashMap<>();
        HashMap<Integer,Integer> mapMax = new HashMap<>();
        for (int i = 1; i <= doctors.size(); i++) {
            mapMax.put(i,0);
        }
        for (int i = 1; i <= 7; i++) {
            int j=1;
            while (j<5){
                Random rand = new Random();
                int random=rand.nextInt(7)+1;//[1,7]内的随机整数
                if(mapMax.get(random) < 4){
                    ArrayList<Integer> integers = maps.get(i);
                    if (integers != null && integers.contains(random)&& i!=7) {
                    } else {
                        if(integers == null) {
                            integers = new ArrayList<Integer>();
                        }
                        mapMax.put(random, mapMax.get(random) + 1);
                        integers.add(random);
                        maps.put(i, integers);
                        j++;
                    }
                }
            }
        }
        return maps;
    }
    public static HashMap doctorIn(){
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 1; i <= 7; i++) {
            map.put(i,i);
        }
        return  map;
    }


    public static void setRedisTemplate(RedisTemplate redisTemplate) {
        paiban.redisTemplate = redisTemplate;
    }
}
